package com.sizu.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.common.dto.RoleDto;
import com.sizu.common.dto.UserDto;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.TRole;
import com.sizu.entity.TUserRole;
import com.sizu.service.ITRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.List;

/**
 *
 * @author 高旌洋
 * @since 2020-02-24
 */
@RestController
@RequestMapping("/user/role")
public class TRoleController {

    @Autowired
    private ITRoleService itRoleService;

    @RequestMapping("/roleList")
    public ResultEntity roleList(){
        List<TRole> tRoles = itRoleService.selectList(null);
        return ResultEntity.ok(tRoles);
    }

//    @RequestMapping("/getRoleMenu")
//    public ResultEntity getRoleMenu(Integer id){
//        List<TRole> roleMenu = itRoleService.getRoleMenu(id);
//        return ResultEntity.ok(roleMenu);
//    }

    //添加角色的方法
    @RequestMapping("/addRole")
    public ResultEntity addRole(RoleDto roleDto){
        TRole tRole = new TRole();
        BeanUtils.copyProperties(roleDto,tRole);
        itRoleService.insert(tRole);
        return ResultEntity.ok();
    }

    //删除角色的方法
    @RequestMapping("/delete")
    public ResultEntity delete(Integer id){
        Wrapper<TRole> wrapper = new EntityWrapper<TRole>();
        wrapper.eq("id",id);
        itRoleService.delete(wrapper);
        return ResultEntity.ok();
    }

    //做修改的方法
    @RequestMapping("/update")
    public ResultEntity update(RoleDto roleDto){
        TRole tRole = new TRole();
        BeanUtils.copyProperties(roleDto,tRole);
        itRoleService.updateById(tRole);
        return ResultEntity.ok();
    }


}
